package io;

import java.io.*;

/**
 * @author IT枫斗者
 * @ClassName BufferedOutputStreamDemo.java
 * @From www.javatiaozao.com
 * @Description TODO
 */
public class BufferedOutputStreamDemo {
    public static void main(String[] args) throws Exception {
        //字节缓冲输出流BufferedOutputStream(OutputStream out) 创建字节缓冲输出流对象
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("myStream\\333.txt"));
        //写数据
        bos.write("aaa\r\n".getBytes());
        bos.write("bbb\r\n".getBytes());
        //关闭资源
        bos.close();
        //创建字节输入流对象BufferedInputStream(InputStream in) 创建字节缓冲输入流对象
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("myStream\\333.txt"));
        //1：一次读取一个字节
//        int by;
//        while ((by=bis.read()) != -1){
//            System.out.println((char)by);
//        }
        //2：读取一个字节数组的1024及其整数倍

        byte[] bys = new byte[1024];
        int len;
        while ((len=bis.read(bys)) != -1){
            System.out.println(new String(bys,0,len));
        }
        //关闭资源
        bis.close();
    }
}
